#ifndef USBHELPER_H
#define USBHELPER_H



#include <QMutex>
#include <QScopedPointer>

#include "content/USBPPControl.h"
#include "content/LibUSBControl.h"


namespace USB {
    typedef enum Control_Tag{
        LibUSB_MODE =(0u),
        USBPP ,
        TAG_ALL
    }REQUEST_MODE;
    //static Serial::REQUEST_MODE current_mode =  Serial::QT_MODE; /// Serial::QT_MODE;
    static USB::REQUEST_MODE current_mode =  USB::LibUSB_MODE; /// Serial::QT_MODE;
}



class USBHelper
{
public:
    static USBHelper* GetInstance(){
        static QMutex mutex;
        static QScopedPointer<USBHelper> inst;
        if (Q_UNLIKELY(!inst)) {
            mutex.lock();
            if (!inst) {
                inst.reset(new USBHelper);
            }
            mutex.unlock();
        }
        return inst.data();
    }


    /// 获取内部成员指针
    std::shared_ptr<USBBase> p() {
        return _mPtr;
    }
private:

    USBHelper();

private:
    static std::shared_ptr<USBBase> _mPtr ;

    void init(){

        switch (USB::current_mode) {
        case USB::LibUSB_MODE:
            _mPtr.reset(new LibUSBControl);
            break;
        case USB::USBPP:
            _mPtr.reset(new USBPPControl);
            break;
        default:
            _mPtr.reset(new USBBase);
            break;
        }
        //mySerial.get()->_sigUpdate.connect(_sigUpdate);
    }

};



#endif // USBHELPER_H
